<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取元素节点对象的方式</title>
</head>
<body>
    <h2>你要买什么课程?</h2>
    <p title='请您选择购买的课程'>本课程是web全栈课程,期待你的购买!</p>
    <ul id='classList'>
        <li class='item'>JavaScript</li>
        <li class='item'>css</li>
        <li>DOM</li>
    </ul>

    <!-- 节点类型:
         1. 元素节点
         2. 属性节点
         3. 文本节点
    -->

    <script type="text/javascript">
        // 1. document.getElementById()  单个对象
        var eleNode = document.getElementById('classList');
        // console.log(eleNode);
        // console.log(typeof eleNode);

        // 2. document.getElementsByTagName() 获取出来的是一个节点对象集合   有点像数组 push()
        var oLis = document.getElementsByTagName('li');
        var oTitle = document.getElementsByTagName('h2');
        console.log(oTitle[0]);

        // console.log(oLis.length);
        for(var i = 0; i < oLis.length; i++){
            // console.log(oLis[i]);
        }
        // console.log(typeof oLis);

        // 3. document.getElementsByClassName()
        var oItems = document.getElementsByClassName('item');
        console.log(oItems[0]);
    </script>
</body>
</html>